package com.kaola.qrcodescanner.qrcode;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;

import com.kaola.qrcodescanner.R;
import com.kaola.qrcodescanner.qrcode.encode.EncodHandler;

public class EncodeActivity extends AppCompatActivity {
    ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_encode);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        image = (ImageView) findViewById(R.id.image);

        final int qrwidth = getResources().getDimensionPixelOffset(R.dimen.qr_width);
        String saveFilePath = getCacheDir().getAbsolutePath() + "/test.jpg";
//        String saveFilePath = getExternalCacheDir().getAbsolutePath() + "/test.jpg";
        //1
//        EncodHandler.createQRImage("{\"expire\":false,\"qrcode_login\":true,\"role\":1,\"time\":\"2016-09-07 11:01:32\",\"uuid\":\"00000000-6a4c-93f3-0033-c5870033c587\"}",
//                qrwidth, qrwidth,
//                BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher),
//                saveFilePath);
//        image.setImageBitmap(BitmapFactory.decodeFile(saveFilePath));


        //2
//        Bitmap qrcode = EncodHandler.createQRImage("{\"expire\":false,\"qrcode_login\":true,\"role\":1,\"time\":\"2016-09-07 11:01:32\",\"uuid\":\"00000000-6a4c-93f3-0033-c5870033c587\"}",
//                qrwidth, qrwidth,
//                BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
//        image.setImageBitmap(qrcode);

        //3
//        Bitmap qrcode = EncodHandler.createQRImageCultMargin("{\"expire\":false,\"qrcode_login\":true,\"role\":1,\"time\":\"2016-09-07 11:01:32\",\"uuid\":\"00000000-6a4c-93f3-0033-c5870033c587\"}",
//                qrwidth, qrwidth,
//                //BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)
//                null
//                , 0);
//        image.setImageBitmap(qrcode);

        //3
//        EncodHandler.createQRImageCultMargin("{\"expire\":false,\"qrcode_login\":true,\"role\":1,\"time\":\"2016-09-07 11:01:32\",\"uuid\":\"00000000-6a4c-93f3-0033-c5870033c587\"}",
//                qrwidth, qrwidth,
//                //BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)
//                null,
//                0,
//                saveFilePath
//        );
//        image.setImageBitmap(BitmapFactory.decodeFile(saveFilePath));
        //4
        Bitmap qrcode = EncodHandler.createQRImageColorfull("{\"expire\":false,\"qrcode_login\":true,\"role\":1,\"time\":\"2016-09-07 11:01:32\",\"uuid\":\"00000000-6a4c-93f3-0033-c5870033c587\"}",
                qrwidth, qrwidth,
                BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)
        );
        image.setImageBitmap(qrcode);

        //4
//        try {
//            Bitmap qrcode = EncodHandler.createQRImage("{\"expire\":false,\"qrcode_login\":true,\"role\":1,\"time\":\"2016-09-07 11:01:32\",\"uuid\":\"00000000-6a4c-93f3-0033-c5870033c587\"}",
//                    BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)
//            );
//            image.setImageBitmap(qrcode);
//        } catch (WriterException e) {
//            e.printStackTrace();
//        }


        //5
//        try {
//            Bitmap qrcode = EncodingHandler.createQRCode("{\"expire\":false,\"qrcode_login\":true,\"role\":1,\"time\":\"2016-09-07 11:01:32\",\"uuid\":\"00000000-6a4c-93f3-0033-c5870033c587\"}",
//                    qrwidth
//                    //        , EncodingHandler.DEFAULT_HINTS
//            );
//            image.setImageBitmap(qrcode);
//        } catch (WriterException e) {
//            e.printStackTrace();
//        }
    }

}
